using System;
using System.Collections.Generic;
using System.Text;
using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;

using FlatRedBall.Math.Geometry;
using FlatRedBall.Math.Splines;
using BitmapFont = FlatRedBall.Graphics.BitmapFont;
using Cursor = FlatRedBall.Gui.Cursor;
using GuiManager = FlatRedBall.Gui.GuiManager;

#if FRB_XNA || SILVERLIGHT
using Keys = Microsoft.Xna.Framework.Input.Keys;
using Vector3 = Microsoft.Xna.Framework.Vector3;
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;


#endif

namespace NereusGame.Entities.Ships.Enemies
{
	public partial class Enemy
	{
        protected enum EnemyState
        {
            Normal,
            Angry
        }

        protected EnemyState state;
        protected Ship PrimaryTarget;
        protected Ship SecondaryTarget;
        protected Ship TertiaryTarget;
        protected float PrimaryTargetRange;
        protected float SecondaryTargetRange;
        protected float TertiaryTargetRange;

        public const float MEDIUM_HEALTH = 0.70f;
        public const float CRITICAL_HEALTH = 0.25f;
        protected Sprite HealthBar;
        protected const float HEALTHBAR_OFFSET = 0.4f;
        public bool IsNeutralMiner;
        public bool IsBoss;

        protected int points;
       
		private void CustomInitialize()
		{
            PrimaryTargetRange = 0f;
            SecondaryTargetRange = 0f;
            TertiaryTargetRange = 0f;
            state = EnemyState.Normal;
            IsNeutralMiner = false;
            IsBoss = false;
            InitializeHealthBar();

		}

		private void CustomActivity()
		{
            UpdateState();
            UpdateHealthBar();
           // UpdateHealthBarColor();
		}

		private void CustomDestroy()
		{
            SpriteManager.RemoveSprite(HealthBar);
            base.Destroy();

		}

        private static void CustomLoadStaticContent(string contentManagerName)
        {


        }

        // initialize the HealthBar
        private void InitializeHealthBar()
        {
            HealthBar = new Sprite();
            HealthBar.AttachTo(Body, true);
            HealthBar.ScaleY = 0.1f;
            HealthBar.Texture = GreenHP;
            HealthBar.RelativePosition = new Vector3(0, Body.Radius + HEALTHBAR_OFFSET, 0);
            HealthBar.ParentRotationChangesRotation = false;
            HealthBar.ParentRotationChangesPosition = false;
            SpriteManager.AddSprite(HealthBar);
        }

        // upate the HPbar with change in Health
        public void UpdateHealthBar()
        {
            if (CurrentHealth < 0)
            {
                HealthBar.ScaleX = 0;
                return;
            }
            HealthBar.ScaleX = (Body.Radius) * (CurrentHealth / MaxHealth);
        }

        // update HPbar color with change in heatlh
        private void UpdateHealthBarColor()
        {
            if (CurrentHealth <= MaxHealth * CRITICAL_HEALTH)
                HealthBar.Texture = RedHP;
            else if (CurrentHealth <= MaxHealth * MEDIUM_HEALTH)
                HealthBar.Texture = OrangeHP;
            else
                HealthBar.Texture = GreenHP;
        }

        public void SetPrimaryTarget(Ship target)
        {
            PrimaryTarget = target;
        }


        public void SetSecondaryTarget(Ship target)
        {
            SecondaryTarget = target;
        }

        public void SetTertieryTarget(Ship target)
        {
            TertiaryTarget = target;
        }

        public void setAngryState()
        {
            state = EnemyState.Angry;
        }

        public void setNormalState()
        {
            state = EnemyState.Normal;
        }

        protected virtual void NormalState()
        {

        }

        protected virtual void AngryState()
        {

        }

        private void UpdateState()
        {
            if (state == EnemyState.Normal)
                NormalState();
            else
                AngryState();
        }

        public int getPoints()
        {
            return points;
        }

            
	}
}
